package com.example.month11.appupdate.updater.bean;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

public class DownloadBean implements Serializable {
    public String title;
    public String content;
    public String url;
    public String md5;
    public String versionCode;

    public DownloadBean(String title, String content, String url, String md5, String versionCode) {
        this.title = title;
        this.content = content;
        this.url = url;
        this.md5 = md5;
        this.versionCode = versionCode;
    }

    public static DownloadBean parseJson(String response) {
        // 解析json
        try {
            JSONObject responseJson = new JSONObject(response);
            String title = responseJson.optString("title");
            String content = responseJson.optString("content");
            String url = responseJson.optString("url");
            String md5 = responseJson.optString("md5");
            String versionCode = responseJson.optString("versionCode");

            DownloadBean bean = new DownloadBean(title, content, url, md5, versionCode);
            return bean;
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
}
